/**
 * Created on 2007-05-16 13:13
 */
package game.frames;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * @author David Wallin
 * 
 * The main menu frame
 */
public class MainMenuFrame extends BasicFrame
{
	/**
	 * Serializable interface forces this to be declared
	 */
	private static final long		serialVersionUID = -6530021093238924563L;
	private JLabel					m_Welcome;
	private JButton					m_Play;
	private JButton					m_Highscores;
	private JButton					m_Options;
	private JButton					m_Instructions;
	private JButton					m_Credits;
	
	/**
	 * Constructor, calls super with the title of this frame as argument
	 * 
	 * @param title The title of this main menu frame
	 */
	public MainMenuFrame()
	{
		super(new GridBagLayout());
	}
	
	/* (non-Javadoc)
	 * @see frames.BasicFrame#initializeComponent()
	 */
	protected void initializeComponent()
	{
		this.setBackground(Color.black);
		GridBagLayout gridBag =(GridBagLayout)this.getLayout();
		
		GridBagConstraints welcomeConstraints = new GridBagConstraints();
		welcomeConstraints.insets = new Insets(10, 0, 0, 0);
		//welcomeConstraints.gridx = 1;
		welcomeConstraints.gridy = 0;
		welcomeConstraints.gridwidth = 1;
		welcomeConstraints.weightx = 0.5;
		
		GridBagConstraints buttonsPanelConstraints = new GridBagConstraints();
		buttonsPanelConstraints.insets = new Insets(10, 0, 0, 0);
		//buttonsPanelConstraints.gridx = 0;
		buttonsPanelConstraints.gridy = 1;
		/*
		GridBagConstraints playConstraints = new GridBagConstraints();
		playConstraints.insets = new Insets(10, 0, 0, 0);
		playConstraints.gridx = 1;
		playConstraints.gridy = 1;
		playConstraints.gridwidth = 1;
		playConstraints.weightx = 0.5;
		
		GridBagConstraints highscoreConstraints = new GridBagConstraints();
		highscoreConstraints.gridx = 0;
		highscoreConstraints.gridy = 2;
		highscoreConstraints.gridwidth = 3;
		
		GridBagConstraints optionsConstraints = new GridBagConstraints();
		optionsConstraints.gridx = 1;
		optionsConstraints.gridy = 3;
		optionsConstraints.gridwidth = 1;
		optionsConstraints.weightx = 0.5;
		
		GridBagConstraints instructionsConstraints = new GridBagConstraints();
		instructionsConstraints.gridx = 1;
		instructionsConstraints.gridy = 4;
		instructionsConstraints.gridwidth = 1;
		instructionsConstraints.weightx = 0.5;
		
		GridBagConstraints creditsConstraints = new GridBagConstraints();
		creditsConstraints.gridx = 1;
		creditsConstraints.gridy = 5;
		creditsConstraints.gridwidth = 1;
		creditsConstraints.weightx = 0.5;
		*/
		m_Welcome = new JLabel("3tris menu");
		m_Play = new JButton("Play");
		m_Highscores = new JButton("Highscores");
		m_Options = new JButton("Options");
		m_Instructions = new JButton("Instructions");
		m_Credits = new JButton("Credits");
		
		m_Welcome.setHorizontalAlignment(JLabel.CENTER);
		m_Welcome.setForeground(Color.white);
		m_Play.addActionListener(this);
		m_Highscores.addActionListener(this);
		m_Options.addActionListener(this);
		m_Instructions.addActionListener(this);
		m_Credits.addActionListener(this);
		
		JPanel buttonsPanel = new JPanel(new GridLayout(5, 1));
		buttonsPanel.add(m_Play);
		buttonsPanel.add(m_Highscores);
		buttonsPanel.add(m_Options);
		buttonsPanel.add(m_Instructions);
		buttonsPanel.add(m_Credits);
		
		this.addComponent(m_Welcome, gridBag, welcomeConstraints);
		this.addComponent(buttonsPanel, gridBag, buttonsPanelConstraints);
		/*
		this.addComponent(m_Play, gridBag, playConstraints);
		this.addComponent(m_Highscores, gridBag, highscoreConstraints);
		this.addComponent(m_Options, gridBag, optionsConstraints);
		this.addComponent(m_Instructions, gridBag, instructionsConstraints);
		this.addComponent(m_Credits, gridBag, creditsConstraints);
		*/
		this.doLayout();
	}
	
	/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	public void actionPerformed(ActionEvent event)
	{
		Object source = event.getSource();
		
		if(source == m_Play)
		{
			//this.updateFrameSwitchListeners(Frames.PLAY);
			this.updateFrameSwitchListeners(Frames.DIFFICULTY);
		}
		
		if(source == m_Highscores)
		{
			this.updateFrameSwitchListeners(Frames.HIGHSCORES);
		}
		
		if(source == m_Options)
		{
			this.updateFrameSwitchListeners(Frames.OPTIONS);
		}
		
		if(source == m_Instructions)
		{
			this.updateFrameSwitchListeners(Frames.INSTRUCTIONS);
		}
		
		if(source == m_Credits)
		{
			this.updateFrameSwitchListeners(Frames.CREDITS);
		}
	}
}
